// src/utils/dataConverter.js
export const convertJsonToEchartsFormat = (jsonData) => {
  if (!jsonData) return null;
  
  // 如果已经是转换后的格式，直接返回
  if (jsonData.multiSeries !== undefined) {
    return jsonData;
  }
  
  // 转换旧格式数据
  if (jsonData.series) {
    return {
      title: jsonData.title?.text || '',
      multiSeries: true,
      allSeries: jsonData.series.map(series => ({
        seriesInfo: { name: series.name },
        line: series.data.map(item => ({
          value: [item.x, item.y]
        }))
      }))
    };
  }
  
  // 默认返回空数据
  return {
    title: '',
    multiSeries: false,
    line: []
  };
};

export const validateData = (data) => {
  if (!data) return false;
  
  if (data.multiSeries) {
    return Array.isArray(data.allSeries) && 
           data.allSeries.every(series => 
             Array.isArray(series.line) && 
             series.line.every(point => 
               Array.isArray(point.value) && point.value.length === 2
             )
           );
  }
  
  return Array.isArray(data.line) && 
         data.line.every(point => 
           Array.isArray(point.value) && point.value.length === 2
         );
};